Log Inside Dataweave
Use log function to help with debugging DataWeave scripts. A Mule app outputs the results through the DefaultLoggingService, which you can see in the Studio console. Let’s see how we can log inside the dataweave.
I have used the below dataweave expression to log the message from inside the Dataweave Transformation
Input:
{ "status": "success", "data": [ { "id": 1, "employee_name": "Tiger Nixon", "employee_salary": 320800, "employee_age": 61, "profile_image": "" } ] }
Dataweave Expression:
%dw 2.0 output application/java --- log(" Current Time Stamp ",now()) ++ log("Error"," Error From Dataweave ") ++ log(" Employee Id Is ",payload.data[0].id)
Output (You can see on anypoint console),all the logs are printed as shown below:
INFO 2020-04-10 19:58:18,372 [[MuleRuntime].cpuIntensive.06: [logging].loggingFlow.CPU_INTENSIVE @206c4a2a] [event: 85a17471-7b37-11ea-a90d-040e3cd1eac7] org.mule.weave.v2.model.service.DefaultLoggingService$: Current Time Stamp - |2020-04-10T19:58:18.371+05:30| INFO 2020-04-10 19:58:18,373 [[MuleRuntime].cpuIntensive.06: [logging].loggingFlow.CPU_INTENSIVE @206c4a2a] [event: 85a17471-7b37-11ea-a90d-040e3cd1eac7] org.mule.weave.v2.model.service.DefaultLoggingService$: Error - " Error From Dataweave " INFO 2020-04-10 19:58:18,377 [[MuleRuntime].cpuIntensive.06: [logging].loggingFlow.CPU_INTENSIVE @206c4a2a] [event: 85a17471-7b37-11ea-a90d-040e3cd1eac7] org.mule.weave.v2.model.service.DefaultLoggingService$: Employee Id Is - 1
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.
Wowww nice, I dont know about this, thanks teams Mulesy!!!
Great but it will work like below.
log(“current time stamp”++ now())